import torch
import numpy as np


def main():
    # directly from list
    data = [[1, 2], [3, 4]]
    x_data = torch.tensor(data)
    print(f'x_data: {x_data}')

    # from np array
    np_array = np.array(data)
    x_np = torch.from_numpy(np_array)
    print(f'x_np: {x_np}')

    # from other tensors
    x_ones = torch.ones_like(x_data)
    print(f'ones tensor:\n {x_ones} \n')

    x_rand = torch.rand_like(x_data, dtype=torch.float)
    print(f'random tensor:\n {x_rand} \n')

    # create tensor by specify shape
    shape = (2, 4)
    rand_t = torch.rand(shape)
    ones_t = torch.ones(shape)
    zeros_t = torch.zeros(shape)
    print(f'rand tensor:\n {rand_t}\n ones_t:\n {ones_t}\n zeros_t:\n {zeros_t}')


if __name__ == '__main__':
    main()
